package com.health.es.temp;

import com.health.es.util.SearchHits;
import com.health.es.util.query.Query;
import com.health.es.util.repository.ElasticsearchRepository;
import org.elasticsearch.index.query.QueryBuilder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.util.List;

/**
 * @author nqlz
 */
public interface EsCustomRepository<T, ID> extends ElasticsearchRepository<T, ID> {

    /**
     * list 查询多条记录
     *
     * @param query
     * @return
     */
    List<T> selectList(Query query);

    /**
     * 查询集合 lambda 入参
     *
     * @param wrapper
     * @return
     */
    List<T> selectList(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper);


    /**
     * 查询集合,build size =1 nativeQuery >1 boolQuery
     *
     * @param builders
     * @return
     */
    List<T> selectList(QueryBuilder... builders);

    /**
     * 查询排序集合,build size =1 nativeQuery >1 boolQuery
     *
     * @param sort
     * @param builders
     * @return
     */
    List<T> selectList(Sort sort, QueryBuilder... builders);

    /**
     * 查询单个
     *
     * @param query
     * @return
     */
    T searchOne(Query query);


    /**
     * 查询单个,build size =1 nativeQuery >1 boolQuery
     *
     * @param builders
     * @return
     */
    T searchOne(QueryBuilder... builders);

    /**
     * 查询单个 lambda 入参
     *
     * @param wrapper
     * @return
     */
    T searchOne(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper);


    /**
     * 分页查询
     *
     * @param pageable 分页
     * @param builders 条件
     * @return
     */
    EsPage<T> searchPage(Pageable pageable, QueryBuilder... builders);

    /**
     * 分页查询 wrapper 入参
     *
     * @param wrapper
     * @return
     */
    EsPage<T> searchPage(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper);

    /**
     * 返回未修改结果
     * @param wrapper
     * @return
     */
    SearchHits<T> prime(SFunction<QueryWrapper<T>, QueryWrapper<T>> wrapper);
}
